import axios from "axios";
import {getToken} from "../../util/token";
import router from "../../router";
axios.interceptors.request.use(function (config) {

  config.headers.common['token'] = getToken();
  //console.dir(config);
  return config;
}, function (error) {
  // Do something with request error

  console.info("request error: ",error);
  return Promise.reject(error);
});


axios.interceptors.response.use(function(response) {
  // console.log('axios inter resp ',response)

  // 无token，跳转到登陆页
  if (response.status === 403) {
      this.$message({
        type:'error',
        message:"请先登录"
      })
      router.push("/login")
  }
  return response
},(function (error) {

  return Promise.reject(error)
}))

export function getAxios() {
  return axios
}
